home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Dema / betonsoldier_spdemo.exe / {app} / Shaders / skinning.fx < prev   
Encoding:
Text File  |  2005-05-05  |  3.8 KB  |  93 lines

  1. //------------------------------------------------------------------------------------------------------
  2. //------------------------------------------------------------------------------------------------------
  3. //------------------------------------------------------------------------------------------------------
  4.  
  5. struct    CSkinningOutput
  6. {
  7.     float4 SkinnedPosition;
  8.     float3 SkinnedNormal;
  9.     float3 SkinnedBumpTangent;
  10.     float3 SkinnedBumpNormal;
  11. };
  12.  
  13. //------------------------------------------------------------------------------------------------------
  14.  
  15. struct    CSkinningOutput1Bone
  16. {
  17.     float4 SkinnedPosition;
  18.     float3 SkinnedNormal;
  19. };
  20.  
  21. //------------------------------------------------------------------------------------------------------
  22.  
  23. inline CSkinningOutput ComputeSkinning4Bones    (const float3 inputPosition, const float3 inputNormal, const float3 inputBumpTangent, const float3 inputBumpNormal, 
  24.                                                  const float4 bonesIndex, const float3 boneWeight,const matrix boneArray[18]);
  25.                                                  
  26. //------------------------------------------------------------------------------------------------------
  27.  
  28. inline CSkinningOutput1Bone ComputeSkinning1Bone        (const float3 inputPosition, const float3 inputNormal, 
  29.                                                  const float4 bonesIndex, const float3 boneWeight,const matrix boneArray[18]);
  30.  
  31. //------------------------------------------------------------------------------------------------------
  32. //------------------------------------------------------------------------------------------------------
  33. //------------------------------------------------------------------------------------------------------
  34.  
  35. inline CSkinningOutput ComputeSkinning4Bones    (const float3 inputPosition, const float3 inputNormal, const float3 inputBumpTangent, const float3 inputBumpNormal, 
  36.                                                  const float4 bonesIndex, const float3 boneWeight,const matrix boneArray[18])
  37. {
  38.     CSkinningOutput output;
  39.     
  40.     matrix accumulatedMatrix;
  41.     
  42.     float index0 = bonesIndex.z * 256.0f;
  43.     float index1 = bonesIndex.y * 256.0f;
  44.     float index2 = bonesIndex.x * 256.0f;
  45.     float index3 = bonesIndex.w * 256.0f;
  46.     
  47.     float weight4 = 1.0f - (boneWeight.x + boneWeight.y + boneWeight.z);
  48.     
  49.     accumulatedMatrix = boneWeight.x * boneArray[index0];
  50.     accumulatedMatrix += boneWeight.y * boneArray[index1];
  51.     accumulatedMatrix += boneWeight.z * boneArray[index2];
  52.     accumulatedMatrix += weight4 * boneArray[index3];
  53.     
  54.     float4 pos;
  55.     
  56.     pos.xyz = inputPosition;
  57.     pos.w = 1.0f;
  58.     
  59.     output.SkinnedPosition = mul (pos,accumulatedMatrix);
  60.     
  61.     output.SkinnedBumpTangent = mul (inputBumpTangent,accumulatedMatrix);
  62.     output.SkinnedBumpNormal = mul (inputBumpNormal,accumulatedMatrix);
  63.     output.SkinnedNormal = mul (inputNormal,accumulatedMatrix);
  64.     
  65.     
  66.     return output;
  67. }
  68.  
  69. //------------------------------------------------------------------------------------------------------
  70. //------------------------------------------------------------------------------------------------------
  71. //------------------------------------------------------------------------------------------------------
  72.  
  73. inline CSkinningOutput1Bone ComputeSkinning1Bone        (const float3 inputPosition, const float3 inputNormal, 
  74.                                                  const float4 bonesIndex, const float3 boneWeight,const matrix boneArray[18])
  75. {
  76.     CSkinningOutput1Bone output;
  77.     
  78.     float index0 = bonesIndex.z * 256.0f;
  79.  
  80.     float4 pos;
  81.     
  82.     pos.xyz = inputPosition;
  83.     pos.w = 1.0f;
  84.     
  85.     output.SkinnedPosition = mul (pos,boneArray[index0]);
  86.     output.SkinnedNormal = mul (inputNormal,boneArray[index0]);
  87.     
  88.     return output;
  89. }
  90.  
  91. //------------------------------------------------------------------------------------------------------
  92. //------------------------------------------------------------------------------------------------------
  93. //------------------------------------------------------------------------------------------------------